<?php
!function_exists('adminmsg') && die('Forbidden');

if(!$step){
	//require_once(D_P.'data/cache/config.php');
	ifcheck($very['open'],'open');
	ifcheck($very['rewrite'],'rewrite');
	ifcheck($very['gzip'],'gzip');
	ifcheck($very['autopage'],'autopage');
	ifcheck($very['rewrite'],'rewrite');
	ifcheck($very['aggrebbs'],'aggrebbs');
	ifcheck($very['aggreblog'],'aggreblog');
	ifcheck($very['ckcomment'],'ckcomment');
	ifcheck($very['ckadmin'],'ckadmin');
	ifcheck($very['skipgif'],'skipgif');
	ifcheck($very['convert'], 'convert');
	ifcheck($very['nbc'], 'nbc');
	ifcheck($very['flashview'], 'flashview');
	ifcheck($very['editor'], 'editor');
	if($very['attachmkdir']){
		$attachdir_ck[$very['attachmkdir']]="checked";
	}
	if($very['htmmkdir']){
		$htmmkdir[$very['htmmkdir']]="checked";
	}
	$discate = explode(',',$very['discate']);
	require_once(R_P.'require/class_cate.php');
	$cate = new Cate();
	$cate_select=$cate->tree();
	foreach ($discate as $cid)
	{
		$cate_select = str_replace("value=\"$cid\"","value=\"$cid\" selected ",$cate_select);
		$cate_moreset .= "<tr class=tr1><td>".$catedb[$cid]['cname']."</td><td>  <input type=\"checkbox\" name=\"includechild[]\" value=\"".$cid."\"";
		in_array($cid,$includechild) && $cate_moreset.=" CHECKED";
		$cate_moreset .= "> &nbsp;&nbsp;".$lang['includechild']."</td><td>&nbsp;&nbsp;  ";
		if($displaynum[$cid]<=0) $displaynum[$cid]=10; //默认显示数量
		$cate_moreset .= " <input type=\"text\" name=\"displaynum[$cid]\" class=\"input\" size=3 value=\"".$displaynum[$cid]."\"/>  ".$lang['displaynum']."</td></tr>   ";
	}
	
	$tplname = array('default');
	$tpath = opendir(R_P . 'template');
	while ($dirname = readdir($tpath))
	{
		if (in_array($dirname, array('.', '..', 'admin','default')))
		{
			continue;
		}
		else 
		{
			array_push($tplname, $dirname);
		}
	}
	include_once(D_P . 'data/cache/server.php');
	$server_select = '';

	foreach ($server as $key => $val)
	{
		$server_select .= "<option value='$key' ";
		if ($key == $very['serverid'])
		{
			$server_select .= "selected";
		}
		$server_select .= ">$val[servername] </option>";
	}

	if($very['aggrebbs']){
		require_once GetLang('extension');
		$bbsmembers = array(
		'todaypost'	=>	$lang['bbs_tpost'],
		'monthpost'	=>	$lang['bbs_mpost'],
		'postnum'	=>	$lang['bbs_postnum'],
		'money'		=>	$lang['bbs_money'],
		'rvrc'		=>	$lang['bbs_rvrc'],
		'credit'	=>	$lang['bbs_credit'],
		);
		$bbsforums = array(
		'tpost'		=>	$lang['bbs_tpost'],
		'article'	=>	$lang['bbs_article'],
		'topic'		=>	$lang['bbs_topic'],
		);
		foreach ($bbsforums as $key=>$f){
			$bbs_forum_select.="<option value=\"$key\"";
			($key==$very['bbs_forumsort']) && $bbs_forum_select.=" SELECTED";
			$bbs_forum_select.=">$f</option>";
		}
		foreach ($bbsmembers as $key=>$m){
			$bbs_member_select.="<option value=\"$key\"";
			($key==$very['bbs_membersort']) && $bbs_member_select.=" SELECTED";
			$bbs_member_select.=">$m</option>";
		}
	}
	if($very['aggreblog']){
		require_once GetLang('extension');
		$blogmembers = array(
		'blogs'		=>	$lang['blog_num'],
		'msgs'		=>	$lang['blog_msgs'],
		//	'friendview'=>	$lang['blog_foot'],
		'todaypost'	=>	$lang['blog_tpost'],
		);
		$blogtags = array(
		'blognum'	=>	$lang['blog_blognum'],
		'photonum'	=>	$lang['blog_photonum'],
		'goodsnum'	=>	$lang['blog_goodsnum'],
		'bookmarknum'=>	$lang['blog_bookmarknum'],
		'filenum'	=>	$lang['blog_filenum'],
		'musicnum'	=>	$lang['blog_musicnum'],
		'allnum'	=>	$lang['blog_allnum'],
		);
		foreach ($blogtags as $key=>$f){
			$blog_tags_select.="<option value=\"$key\"";
			($key==$very['blog_forumsort']) && $blog_tags_select.=" SELECTED";
			$blog_tags_select.=">$f</option>";
		}
		foreach ($blogmembers as $key=>$m){
			$blog_member_select.="<option value=\"$key\"";
			($key==$very['blog_membersort']) && $blog_member_select.=" SELECTED";
			$blog_member_select.=">$m</option>";
		}
	}
	//$very['loginip = str_replace(",","\n",$very['loginip);
	if($very['lang']=='gbk'){
		$gbkselect='selected';
	}elseif ($very['lang']=='utf-8'){
		$utf8select='selected';
	}
}
elseif ($step==2)
{
	/*
	!is_dir(D_P.$config['htmdir']) && Showmsg('config_htmdir');
	!is_writable(D_P.$config['htmdir']) && Showmsg('config_htmdirwrite');
	!is_dir(D_P.$config['attachdir']) && Showmsg('config_attachdir');
	!is_writable(D_P.$config['attachdir']) && Showmsg('config_attachdirwrite');
	*/
	empty($config['title']) && Showmsg('config_notitle');
	empty($config['datefm']) && Showmsg('config_notimedf');
	$d = array();
	foreach ($discate as $c){
		$c = intval($c);
		$d[] = $c;
	}
	$config['discate']=implode(',',$d);
	$config['cvtime']=(int)$config['cvtime'];
	$config['perpage']=(int)$config['perpage'];
	
	if (!empty($_FILES['logo']['name']))
	{
		$logoext = strtolower(end(explode('.', $_FILES['logo']['name'])));
		if (!in_array($logoext, array('jpg', 'jpeg', 'png', 'gif')))
		{
			Showmsg('LOGO格式不符合要求');
		}
		move_uploaded_file(stripslashes($_FILES['logo']['tmp_name']), D_P . 'data/logo.' . $logoext);
		$config['logo'] = $logoext;
	}
	
	foreach ($config as $key=>$value){
		$key = 'db_'.$key;
		$value = addslashes($value);
		$db->pw_update(
		"SELECT * FROM cms_config WHERE db_name='$key'",
		"UPDATE cms_config SET db_value='$value' WHERE db_name='$key'",
		"INSERT INTO cms_config (db_name,db_value) VALUES('$key','$value')"
		);
	}
	require_once(R_P.'require/class_cache.php');
	$cache = new Cache();
	$cache->config();
	adminmsg('set_saveok');
}
require PrintEot('header');
require PrintEot('set_config');
adminbottom();
?>